import Vue from 'vue'
import Router from 'vue-router'

import Login from '@/components/Login/Login'
import Personal from '@/components/Login/Personal'

import Home from '@/components/Home/Home'
import Header from '@/components/Common/Header'
import Base from '@/components/Common/Base'
import Project from '@/components/Aside/Project/Project'
import Addpjt from '@/components/Aside/Project/Addpjt'

import Module from '@/components/Aside/Module/Module'
import Addmodule from '@/components/Aside/Module/Addmodule'

import Attachment from '@/components/Aside/Attachment/Attachment'
import AddAttachment from '@/components/Aside/Attachment/AddAttachment'

import Database from '@/components/Aside/Database/Database'
import Adddatabase from '@/components/Aside/Database/Adddatabase'

import Environment from '@/components/Aside/Environment/Environment'
import Addenvironment from '@/components/Aside/Environment/Addenvironment'

import Api from '@/components/Aside/Api/Api'
import Addapinew from '@/components/Aside/Api/Addapinew'

import ApiDetail from '@/components/Aside/ApiDetail/ApiDetail'
import AddApiDetail from '@/components/Aside/ApiDetail/AddApiDetail'

import Sql from '@/components/Aside/Sql/Sql'
import Addsql from '@/components/Aside/Sql/Addsql'

import Cases from '@/components/Aside/Cases/Cases'
import Addcases from '@/components/Aside/Cases/Addcases'

import CasesDetail from '@/components/Aside/CasesDetail/CasesDetail'
import AddCasesDetail from '@/components/Aside/CasesDetail/AddCasesDetail'

import OftenMyTool from '@/components/Aside/OftenMyTool/OftenMyTool'
import AddOftenMyTool from '@/components/Aside/OftenMyTool/AddOftenMyTool'

import Interval from '@/components/Aside/Interval/Interval'
import EditInterval from '@/components/Aside/Interval/EditInterval'

import CrontabSchedule from '@/components/Aside/CrontabSchedule/CrontabSchedule'
import EditCrontabSchedule from '@/components/Aside/CrontabSchedule/EditCrontabSchedule'
import PeriodicTask from '@/components/Aside/PeriodicTask/PeriodicTask'
import EditPeriodicTask from '@/components/Aside/PeriodicTask/EditPeriodicTask'
import TaskResult from '@/components/Aside/TaskResult/TaskResult'

import MyShell from '@/components/Aside/MyShell/MyShell'
import EditMyShell from '@/components/Aside/MyShell/EditMyShell'

import Automated from '@/components/Aside/Automated/Automated'
import EditAutomated from '@/components/Aside/Automated/EditAutomated'

import AutomatedTaskRecord from '@/components/Aside/AutomatedTaskRecord/AutomatedTaskRecord'


import report from '@/components/Aside/report/report'

import reportDay from '@/components/Aside/report/reportDay'
import reportWeeks from '@/components/Aside/report/reportWeeks'
import reportMonth from '@/components/Aside/report/reportMonth'
import reportYears from '@/components/Aside/report/reportYears'

import ModulePage from '@/components/Aside/WebTest/ModulePage/ModulePage'
import EditModulePage from '@/components/Aside/WebTest/ModulePage/EditModulePage'
import LabelElement from '@/components/Aside/WebTest/LabelElement/LabelElement'
import EditLabelElement from '@/components/Aside/WebTest/LabelElement/EditLabelElement'


import Steps from '@/components/Aside/WebTest/Steps/Steps'
import EditSteps from '@/components/Aside/WebTest/Steps/EditSteps'

import SeleniumFunc from '@/components/Aside/WebTest/SeleniumFunc/SeleniumFunc'
import EditSeleniumFunc from '@/components/Aside/WebTest/SeleniumFunc/EditSeleniumFunc'

import StepsRealize from '@/components/Aside/WebTest/StepsRealize/StepsRealize'
import EditStepsRealize from '@/components/Aside/WebTest/StepsRealize/EditStepsRealize'

import Test from '@/components/Test/Test'
import Jsongs from '@/components/Test/Jsongs'


Vue.use(Router);

// import Router from 'vue-router'

// 解决重复点击导航路由报错
const originalPush = Router.prototype.push;
Router.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
};


const urls = [
  // 1:path,2:name,3:component
  ['/Jsongs', 'Jsongs', Jsongs],  // json格式化工具
  ['/OftenMyTool', 'OftenMyTool', OftenMyTool],  // 常用工具
  ['/AddOftenMyTool', 'AddOftenMyTool', AddOftenMyTool],
  ['/login', 'login', Login], // 登录路由
  ['/personal', 'personal ', Personal], // 个人中心
  ['/base', 'base', Base], // 基础页面
  ['/home', 'Home', Home], // 首页路由
  ['/header', 'Header', Header], // 顶栏路由

  ['/project', 'project', Project], // 项目路由
  ['/projectAdd/', 'add_project', Addpjt], // 添加项目路由
  ['/projectEdit', 'edit_project', Addpjt], // 编辑项目路由

  ['/module', 'module', Module], // 模块路由
  ['/moduleAdd/', 'moduleAdd', Addmodule], // 添加模块路由
  ['/moduleEdit', 'moduleEdit', Addmodule], // 编辑模块路由

  ['/attachment', 'attachment', Attachment],  // 附件模块
  ['/attachmentEdit', 'attachmentEdit', AddAttachment], // 编辑，添加附件

  ['/database', 'database', Database], // 数据库列表
  ['/databaseAdd', 'databaseAdd', Adddatabase],//添加数据库
  ['/databaseEdit', 'databaseEdit', Adddatabase], // 编辑数据库

  ['/environment', 'environment', Environment], // 数据库列表
  ['/environmentAdd', 'environmentAdd', Addenvironment],//添加数据库
  ['/environmentEdit', 'environmentEdit', Addenvironment], // 编辑数据库

  ['/api', 'api', Api], // 接口路由
  ['/addapinew', 'apinewAdd', Addapinew],  // 方式2添加
  ['/addapinew', 'apinewEdit', Addapinew],  // 方式2添加

  ['/sql', 'sql', Sql],
  ['/sqlAdd', 'sqlAdd', Addsql],
  ['/sqlEdit', 'sqlEdit', Addsql],

  ['/ApiDetail', 'ApiDetail', ApiDetail], // 接口明细列表
  ['/ApiDetailAdd', 'ApiDetailAdd', AddApiDetail], // 添加明细
  ['/ApiDetailEdit', 'ApiDetailEdit', AddApiDetail], // 编辑明细

  ['/cases', 'cases', Cases], // 用例路由
  ['/Addcases', 'casesEdit', Addcases],

  ['/casesDetail', 'casesDetail', CasesDetail],  // 用例明细
  ['/EditCasesDetail', 'casesDetailEdit', AddCasesDetail],

  ['/Interval', 'Interval', Interval],
  ['/EditInterval', 'EditInterval', EditInterval],

  ['/CrontabSchedule', 'CrontabSchedule', CrontabSchedule],
  ['/EditCrontabSchedule', 'EditCrontabSchedule', EditCrontabSchedule],


  ['/PeriodicTask', 'PeriodicTask', PeriodicTask],
  ['/EditPeriodicTask', 'EditPeriodicTask', EditPeriodicTask],

  ['/TaskResult', 'TaskResult', TaskResult],

  ['/MyShell', 'MyShell', MyShell],
  ['/EditMyShell', 'EditMyShell', EditMyShell],

  ['/Automated', 'Automated', Automated],
  ['/EditAutomated', 'EditAutomated', EditAutomated],

  ['/AutomatedTaskRecord', 'AutomatedTaskRecord', AutomatedTaskRecord],

  ['/report', 'report', report],
  ['/reportDay', 'reportDay', reportDay],
  ['/reportWeeks', 'reportWeeks', reportWeeks],
  ['/reportMonth', 'reportMonth', reportMonth],
  ['/reportYears', 'reportYears', reportYears],

  ['/ModulePage', 'ModulePage', ModulePage],
  ['/EditModulePage','EditModulePage',EditModulePage],

  ['/LabelElement','LabelElement',LabelElement],
  ['/EditLabelElement','EditLabelElement',EditLabelElement],

  ['/Steps','Steps',Steps],
  ['/EditSteps','EditSteps',EditSteps],

  ['/SeleniumFunc','SeleniumFunc',SeleniumFunc],
  ['/EditSeleniumFunc','EditSeleniumFunc',EditSeleniumFunc],

  ['/StepsRealize','StepsRealize',StepsRealize],
  ['/EditStepsRealize','EditStepsRealize',EditStepsRealize],

  ['/test', 'test', Test], // 用例路由

];

const getURL = () => {
  let urlData = [];
  urlData.push({'path': '/', 'redirect': '/home'});
  urls.forEach(uls => {
    urlData.push({'path': uls[0], 'name': uls[1], 'component': uls[2]})
  });
  return urlData
};

export default new Router({
  // mode: 'history',//改成history模式
  routes: getURL(),
})
